﻿using Microsoft.EntityFrameworkCore;
using Project.Domain.AggregateModels;
using Project.Domain.Seedwork;
using Project.Infrastructure.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Project.Infrastructure.Repositories
{
    public class ProjectRepository
        : IProjectRepository
    {
        private readonly ProjectContext _dbContext;
        public ProjectRepository(ProjectContext dbContext)
        {
            _dbContext = dbContext;
        }
        public IUnitOfWork UnitOfWork => _dbContext;

        public async Task AddAsync(Domain.AggregateModels.Project project)
        {
            await _dbContext.AddAsync(project);
        }

        public async Task<Domain.AggregateModels.Project> GetAsync(int projectId)
        {
            return await _dbContext.Project.AsNoTracking()
                .Include(p => p.Properties)
                .Include(p => p.Viewers)
                .Include(p => p.Contributors)
                .Include(p => p.BPFiles)
                .Include(p => p.ProjectVisibleRule)
                .FirstOrDefaultAsync(p => p.Id == projectId);
        }

        public void Update(Domain.AggregateModels.Project project)
        {
            _dbContext.Update(project);
        }
    }
}
